/**
 * @param {string} s
 * @return {string}
 */
var reverseWords = function(s) {
  s = s.trim();
  let arr = s.split(" ");
  for(let i = 0; i < arr.length; i++) {
    if(!arr[i]) {
      arr.splice(i, 1);
      i--;
    }
  }
  return arr.reverse().join(" ");
};
let s = "the sky is blue";
console.log(reverseWords(s));
s = "  hello world  ";
console.log(reverseWords(s));
s = "a good   example";
console.log(reverseWords(s));
